package com.p595263720.o_amap.map.models;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.amap.api.maps.AMap;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.p595263720.o_amap.R;

import java.util.Map;

public class InfoWinAdapterForLSJ implements AMap.InfoWindowAdapter {
    private Context mContext;

    public InfoWinAdapterForLSJ(Context context) {
        this.mContext = context;
    }


    private int LSJ_DRIVER_ACCEPT_ORDER_FLAG = 1;// 车主接单显示infowindow
    private int LSJ_SHIPPER_SELECT_POINT_FLAG = 2;// 货主发货选点

    private LatLng latLng;
    private String snippet;
    private String title;
    private String dic_time;
    Map<String, Object> map;


    @Override
    public View getInfoWindow(Marker marker) {
        if (marker.getObject() != null) {
            map = (Map<String, Object>) marker.getObject();
        }
        initData(marker);
        View view = initView(map);
        return view;
    }

    private void initData(Marker marker) {
        latLng = marker.getPosition();
        snippet = marker.getSnippet();
        title = marker.getTitle();
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    private View initView(Map<String, Object> map) {

        try {
            View view = null;
            double infoWindowFlag = (double) map.get("infoWindowFlag");
            if ((int) infoWindowFlag == LSJ_DRIVER_ACCEPT_ORDER_FLAG) {
                dic_time = (String) map.get("dic_time");
                view = LayoutInflater.from(mContext).inflate(R.layout.view_infowindow, null);
                TextView titleView = (TextView) view.findViewById(R.id.freight);
                TextView snippetView = (TextView) view.findViewById(R.id.distance);
                TextView time = (TextView) view.findViewById(R.id.dic_time);
                titleView.setText(title);
                snippetView.setText(snippet);
                time.setText(dic_time);
            }
            if ((int) infoWindowFlag == LSJ_SHIPPER_SELECT_POINT_FLAG) {
                view = LayoutInflater.from(mContext).inflate(R.layout.lsj_shipper_select_point_flag, null);
                TextView titleView = (TextView) view.findViewById(R.id.address);
                TextView snippetView = (TextView) view.findViewById(R.id.detailed_address);
                titleView.setText(title);
                snippetView.setText(snippet);
            }
            return view;
        } catch (Exception e) {

        }
        return null;
    }
}
